﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace VisionEstereo.SegmentacionColores
{
    public class Clase
    {
        public ArrayList listaElementos;
        public PixelDato centro;
        public double sumaB, sumaG, sumaR;
        int nElem;

        public Clase(PixelDato pixel)
        {
            listaElementos = new ArrayList();
            sumaB = 0; sumaG = 0; sumaR = 0;
            addElement(pixel);
        }

        public Clase()
        {
            listaElementos = null;
        }
       
        public Clase(Clase clase) /*Constructora por copia*/
        {
            this.listaElementos = clase.listaElementos;
            this.centro = clase.centro;
            this.sumaR = clase.sumaR;
            this.sumaG = clase.sumaG;
            this.sumaB = clase.sumaB;
            this.nElem = clase.nElem;
        }

        private void sumaElemento(byte azul, byte verde, byte rojo)
        {
            sumaB = (double)azul;
            sumaG = (double)verde;
            sumaR = (double)rojo;
        }

        public PixelDato getCentro()
        {
            return centro;
        }

        public ArrayList getLista()
        {
            return listaElementos;
        }

        public void addElement(PixelDato elemento)
        {
            double azul = 0, rojo = 0, verde = 0;
            listaElementos.Add(elemento);
            nElem++;

            sumaB += (double) elemento.Blue;
            sumaG += (double) elemento.Green;
            sumaR += (double) elemento.Red;
            azul = sumaB / nElem;
            rojo = sumaR / nElem;
            verde = sumaG / nElem;
            centro = new PixelDato((byte)azul, (byte)verde, (byte)rojo);
        }
    }
}
